package com.hrms.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.hrms.pojo.Train;
import com.hrms.service.impl.TrainServiceImpl;

/**
 * 类名称：TrainController.java<br>
 * 类描述：<br>
 * 创建时间：2017年3月20日, 上午10:08:03
 */
@Controller
@RequestMapping("/train")
public class TrainController {
	@Resource
	private TrainServiceImpl trainServiceImpl;
	//	培训模块引导页面
	@RequestMapping("/trainLogin")
	private ModelAndView  LoginTrainController(HttpServletRequest request,HttpServletResponse response) {
		return new ModelAndView("train/trainLogin");
	}
	//	添加培训欢迎界面
	@RequestMapping("/addTrain")
	private ModelAndView  addTrainController(HttpServletRequest request,HttpServletResponse response) {
		return new ModelAndView("train/addTrain");
	}
	//	返回添加培训
	@RequestMapping(value = "/returnAddTrain", method = RequestMethod.POST)
	private ModelAndView  returnAddTrainController(HttpServletRequest request,HttpServletResponse response) {
		try{
			Train trainDemo =new Train();
			trainDemo.setTrainMan(request.getParameter("trainManForAdd"));
			trainDemo.setTrainTitle(request.getParameter("trainTitleForAdd"));
			trainDemo.setTrainContent(request.getParameter("trainContentForAdd"));
			trainDemo.setTrainTime(request.getParameter("trainTimeForAdd"));
			trainDemo.setTrainAddress(request.getParameter("trainAddressForAdd"));
			trainDemo.setTrainJoin(request.getParameter("trainJoinForAdd"));
			trainDemo.setTrainBz(request.getParameter("trainBzForAdd"));
			trainServiceImpl.addTrain(trainDemo);
			return new ModelAndView("train/successful");
		}catch(Exception e){
			e.printStackTrace();
			return new ModelAndView("train/addTrain");
		}

	}
	//	删除培训
	@RequestMapping("/deleteTrain/{id}")
	private ModelAndView  deleteTrainController(HttpServletRequest request,HttpServletResponse response,@PathVariable("id")Integer id) {
		try{
			trainServiceImpl.deleteTrain(id);
			return new ModelAndView("train/deleteTrain");
		}catch(Exception e){
			e.printStackTrace();
			return new ModelAndView("error");
		}

	}
	//	查看培训
	@RequestMapping("/selectAllTrain")
	private ModelAndView  seleteAllTrainController(HttpServletRequest request,HttpServletResponse response) {
		List<Train> returnSeleteAllTrain =trainServiceImpl.selectAllTrain();
		return new ModelAndView("train/selectAllTrain","returnSeleteAllTrain",returnSeleteAllTrain);
	}
	//	详查培训
	@RequestMapping("/selectByIdTrain/{id}")
	private ModelAndView selectByIdTrainController(HttpServletRequest request,HttpServletResponse response,@PathVariable("id")Integer id) {
		try{
			Train trainDemo=trainServiceImpl.selectByIdTrain(id);
			return new ModelAndView("train/selectByIdTrain","returnSelectByIdTrain",trainDemo);
		}catch(Exception e){
			e.printStackTrace();
			return new ModelAndView("error");
		}


	}
}
